package com.atguigu.test01;

public class test001 {
    public static void main(String[] args) {
        int [] arrays = new int[]{1,11,22,33,77,99,103};
        int target = 77;
        System.out.println(binarySearch(arrays,target));
    }

    public static int binarySearch(int [] arraySorted,int target){
        int left = 0;
        int right = arraySorted.length-1;
        while (left <= right){
            int middle = left + (right - left)/2;
            if (arraySorted[middle] == target){
                return middle;
            }else if (arraySorted[middle]>target){
                right = middle-1;
            }else {
                left = middle + 1;
            }
        }
        return -1;
    }
}
